{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import portfolioopt as pfopt\n",
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/v-fech/Barra_model/portfolioopt.py:116: UserWarning: Convergence problem\n",
      "  warnings.warn(\"Convergence problem\")\n"
     ]
    }
   ],
   "source": [
    "# np.save(\"./data/covariance_matrix.npy\", model_covariance)\n",
    "# np.save(\"./data/return.npy\",R)\n",
    "\n",
    "\n",
    "cov_mat=np.load(\"./data/covariance_matrix.npy\")\n",
    "\n",
    "avg_rets=np.load(\"./data/return.npy\")\n",
    "\n",
    "target_ret=0.001\n",
    "\n",
    "calc_weights = pfopt.markowitz_portfolio(pd.DataFrame(cov_mat[-1]), pd.Series(avg_rets[-1]), target_ret).values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.04007575, 0.01968392, 0.04482278, 0.00166649, 0.00215495,\n",
       "       0.00698555, 0.00260674, 0.05317759, 0.2319438 , 0.02850398,\n",
       "       0.00367933, 0.00719721, 0.00580692, 0.00214396, 0.0293379 ,\n",
       "       0.02848679, 0.01174723, 0.00721944, 0.02945401, 0.0028964 ,\n",
       "       0.0266157 , 0.02529467, 0.01134095, 0.03720998, 0.01391926,\n",
       "       0.02147662, 0.00622947, 0.02595904, 0.00181997, 0.00512509,\n",
       "       0.00164757, 0.0081678 , 0.00888888, 0.001331  , 0.00482084,\n",
       "       0.02744277, 0.03327901, 0.00172312, 0.04182935, 0.0191704 ,\n",
       "       0.00549733, 0.00293706, 0.00751629, 0.00551583, 0.05175973,\n",
       "       0.00446948, 0.00237201, 0.00158538, 0.00735794, 0.02810673])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "calc_weights "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
